function show_detail(e){
    console.log(e);
    var e = e.target || e.toElement;
    while(true){
        if( e.className.search('log') >=0 ){
            break;
        }
        e = e.parentElement;
    }
    var box = e.parentElement;
    var exc = box.getElementsByClassName('exception');
    if( exc.length ){
        $(exc[0]).toggle();
    }
    var detail = box.getElementsByClassName('detail');
    $(detail).toggle();
}

var reload = false;
function on_log_saved(data){
    console.log(data);
    reload = true;
}

function clock()
{
    if(reload){
        reload = false
        window.location.href = window.location.href;
    }
}

$(document).ready(function() {
    console.log('ready');
	$('.log').on('click', show_detail);
	var sock = io('/log');
    sock.on('connect',
        function() {
            console.log("connect");
        });
    sock.on('disconnect',
        function(){
            sock.disconnect();
        });
    sock.on('saved', on_log_saved);

    if(self != top){
        setInterval("clock()",60000);
        console.log("in iframe");
    }
} );



